package cn.iocoder.yudao.module.carbon.api.gas;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.carbon.api.gas.dto.GasRespDTO;
import cn.iocoder.yudao.module.carbon.controller.admin.gase.vo.GaseExportReqVO;
import cn.iocoder.yudao.module.carbon.convert.gase.GaseConvert;
import cn.iocoder.yudao.module.carbon.dal.dataobject.gase.GaseDO;
import cn.iocoder.yudao.module.carbon.service.gase.GaseService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.system.enums.ApiConstants.VERSION;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class GasApiImpl implements GasApi {

    @Resource
    private GaseService gaseService;

    @Override
    public CommonResult<List<GasRespDTO>> getGasList() {
        List<GaseDO> gaseList = gaseService.getGaseList(new GaseExportReqVO());
        return success(GaseConvert.INSTANCE.convertList03(gaseList));
    }

    @Override
    public CommonResult<Map<Long, GasRespDTO>> getGasMap(Collection<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return success(Collections.emptyMap());
        }
        List<GaseDO> gaseDOList = gaseService.getGaseList(ids);
        List<GasRespDTO> gasRespDTOList = GaseConvert.INSTANCE.convertList03(gaseDOList);
        return success(CollectionUtils.convertMap(gasRespDTOList, GasRespDTO::getId));
    }
}
